<?php
/**
 * Created by PhpStorm.
 * User: xiaoxin
 * Date: 2018/10/29 0029
 * Time: 15:05
 */

namespace app\index\controller;
use app\index\model\User;
use think\Controller;
use think\captcha\Captcha;
use think\Loader;

class Reg extends Controller
{
	/**
	 * 注册页面主页
	 * @return mixed
	 */
	public function index(){
		$this->assign('title', '注册');
		return $this->fetch();
	}


	/**
	 * 生成验证码方法
	 */
	public function code(){
		$config =    [
			// 验证码字体大小
			'fontSize'    =>    20,
			// 验证码位数
			'length'      =>    3,
			// 关闭验证码杂点
			'useNoise'    =>    false,
		];
		$captcha = new Captcha($config);
		return $captcha->entry();
	}


	/**
	 * 用户注册，成功跳到登陆页面
	 */
	public function checkReg(){
		$post = input('post.');
		$validate = Loader::validate('CheckReg');
		if(!$validate->check($post)){
			$this->error($validate->getError());
		}
		$post['create_time'] = time();
		$post['password'] = md5($post['password']);
		$res = User::create($post);
		if ($res){
			$this->success('注册成功');
		}else{
			$this->error('注册失败，请稍后再试');
		}
	}


//	public function vercode(){
//		$post = input('post.');
//		$validate = Loader::validate('CheckReg');
//		if(!$validate->scene('vercode')->check($post)){
//			$this->error($validate->getError());
//		}
//		$this->sendCode();
//	}
//
//	public function sendCode(){
//
//	}
}